function showPanel(){
    var id = event.target.id;
    var tabid = id.split("-")[0];
    var tag = document.getElementById("myTabs").getElementsByTagName("li");
    var taglength = tag.length;
    for(var i=0;i<taglength;i++){
     document.getElementById(tabid).parentElement.children[i].style.display="none";
    }
    document.getElementById(tabid).style.display="block";
}
//document.getElementById('login').innerHTML="欢迎，小明 |";
//document.getElementById("register").innerHTML="退出";
/* info 个人资料加载*/
var username_login;
var realname;
var gender;
var cellphone;
var area;
var  email;
$(function(){
	var str = window.location.search;
	var num = str.indexOf("?");
	var id = str.substr(num+1);
              $.ajax({
                        type:"POST",
                        dataType:"json",
                        url:"/ajax/info",
                        data:id,
                        headers:{ 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                      },
                      success:function(result){
                              var info = result.info;
                              var type = result.type;
                              var  levelAll="";
                              for(var i=0;i<type.length;i++){
                             	var levelname = type[i].typename;
                                var  levelAll =levelname+"   "+ levelAll;
                              }
                                 realname = info['realname'];
                                 gender = info['gender'];
                                 cellphone = info['cellphone'];
                                 email = info['email'];
                                 area = info['area'];
                                $('#level_info').html(levelAll);
                              	$('#username_info').html(info['username']);
                              	$('#realname_info').html(realname);
                                if(gender==0){
                                        $('#gender_info').html('男');
                                }else{
                                      $('#gender_info').html('女');
                                }
                              	$('#cellphone_info').html(cellphone);
                              	$('#email_info').html(email);
                              	$('#area_info').html(area);
                              	$('#registertime_info').html(info['registetime']);
                                username_login = info['username'];
                              	var user = "欢迎,"+info['username']+" | ";
                               document.getElementById('login').innerHTML=user;
                               document.getElementById("register").innerHTML="退出";
                               $('#register').attr('href','/login');
                               $('#login').removeAttr('href');
                               $('#login').css('color','snow');
                                $('#I_Name').val(realname);
                               $('#I_tel').val(cellphone);
                               $('#I_Area').val(area);
                              $('#I_Email').val(email);
                              $("input[name='gender']")[gender].checked=true;
                      }
                       });
});
       function resetPW(){
                window.location.href="/reset?username="+username_login;
}
/*密码重新设置*/
function passWCheck(){
  var I_UserName='I_UserName='+username_login;
  var  password = 'password='+$('#Pre_passW').val();
  var str = I_UserName+'&'+password;
  $.ajax({
                        type:"POST",
                        dataType:"json",
                        url:"/ajax/checkpassw",
                        data:str,
                        headers:{ 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                      },
                      success:function(result){
                        if(result==true){
                            $('#pre_lab').html('');
                        }else{
                          $('#pre_lab').html('密码输入有误');
                        }
                      }
  });
}
function checknew_PassW(){
  var reg = new RegExp(/^[a-zA-Z0-9_]\w{6,20}$/);
  var newpassw_One= $('#New_passW').val();
  if (newpassw_One.match(reg)) {
                  $(lab_Name).html("不少于6位字符");
                     $('#newset_div').hide();
                } else {
                     if (newpassw_One!=""&&newpassw_One.length < 6) {
                        $('#newset_div').show();
                        $('#newset_lab').html('密码设置有误');
                } else if (newpassw_One.length > 30) {
                         $('#newset_div').show();
                        $('#newset_lab').html('密码设置有误');
            }
            else if(newpassw_One.length >5&& newpassw_One.length <30){
                   $('#newset_div').hide();
            }
        }
}
function  newPassWSame(){
  var newpassw_One= $('#New_passW').val();
  var newpassw_Two =$('#NAgin_passW').val();
  if(newpassw_One!=newpassw_Two){
         $('#reset_div').show();
         $('#reset_lab').html('密码不一致,请重新输入密码');
  }else{
         $('#reset_div').hide();
  }
  
}
$(function(){
  $('#resetbutton').unbind("click").click(function(){
    var password = $('#New_passW').val();
    var str = window.location.search;
    var num = str.indexOf("=");
    var id = str.substr(num+1);
           if($('#New_passW').val()=="" || $('#Pre_passW').val()==""){
            $('#reset_div').show();
            $('#reset_lab').html('信息填写完整');
            return false;
           }else if(  $('#pre_lab').text()=="密码输入有误"){
                            alert("原始密码输入有误");
                            return false;
           }else if($('#New_passW').val()!=$('#NAgin_passW').val()){
                            alert("密码设置不一致");
                            return false;
            }else{
               var str = "username_login="+username_login+"&password="+password;
                 $('#reset_div').hide();
                 $.ajax({
                         type:"POST",
                        dataType:"json",
                        url:"/ajax/resetPW",
                        data:str,
                        headers:{ 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                      },
                      success:function(result){
                        if(result.error==null){
                           iosOverlay({
                           text: "密码修改成功!",
                           duration: 2000,
                           icon: "/image/check.png",
                            onhide : function(){
                               window.location.href="/useraccount?id="+id;
                            },
                          });
                        }else{
                          alert("密码提交失败!");
                        }
                      }
              })
            }
  });
/* 基本信息修改*/
   $("#updatebutton").unbind("click").click(function(){
       var phone = document.getElementById('I_tel').value;
       var re = /^1\d{10}$/;
       var email=document.getElementById('I_Email').value;
       var remail= /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
       if (re.test(phone)&& remail.test(email)) {
               $('#update_div').hide();
       }else {
               $('#update_div').show();
               $('#update_lab').html('手机号或email格式有误,请重新输入!');
               return false;
     }
  });
});